<template>
  <div class="box">
    <span class="title">你确认{{this.operation}}以下数据吗？
    <i class="iconfont icon-icon-test10 icon1"></i>
    </span>
    <el-table
      :data="roleObjs"
      stripe
      style="width: 100%">
      <el-table-column
        prop="roleId"
        label="角色编号"
      >
      </el-table-column>
      <el-table-column
        prop="roleName"
        label="角色姓名"
      >
      </el-table-column>
      <el-table-column
        prop="roleDescription"
        label="角色描述">
      </el-table-column>
      <el-table-column
        label="功能列表"
        width="400"
      >
        <template slot-scope="scope">
          <el-checkbox-group v-model="scope.row.functionList" disabled>
            <el-checkbox label="授权中心" name="type"></el-checkbox>
            <el-checkbox label="转账管理" name="type"></el-checkbox>
            <el-checkbox label="交易管理" name="type"></el-checkbox>
            <el-checkbox label="日志管理" name="type"></el-checkbox>
            <el-checkbox label="个人中心" name="type"></el-checkbox>
          </el-checkbox-group>
        </template>
      </el-table-column>
    </el-table>
    <div class="button-cf">
      <el-button size="medium" type="primary" @click="handleCommit">确认提交</el-button>
      <el-button size="medium" @click="handleBack">返回</el-button>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    name: "rm-confirm",
    data() {
      return {
        operation: '',
        roleObjs: []
      }
    },
    mounted() {
      this.roleObjs = [this.$route.params.roleObj];
      this.operation = this.$route.params.operation;
    },
    methods: {
      handleCommit() {
        //判断是什么操作
        if (this.operation === '录入') {
          axios.post('/api/role/entry', {roleObj: this.$route.params.roleObj}).then(res => {
              if (res.data.status === '1') {
                this.$router.push({name: 'result', params: {operation: this.operation, msg: '成功'}})
              }
            }
          )
        }else if (this.operation === '修改'){
          axios.post('/api/role/modifyRole',{roleObj: this.roleObjs[0]}).then(res=>{
            if (res.data.status === '1') {
              this.$router.push({name: 'result', params: {operation: this.operation, msg: '成功'}})
            }
          })
        }else{
          axios.post('/api/role/delRole',{roleId: this.roleObjs[0].roleId}).then(res=>{
            if (res.data.status === '1') {
              this.$router.push({name: 'result', params: {operation: this.$route.params.operation, msg: '成功'}})
            }
          })
        }
      },
      handleBack() {
        this.$router.push('/roleManagement/management')
      }
    }
  }
</script>

<style scoped>
  .box {
    width: 60%;
    border: 1px solid #0886ea;
    margin: 0 auto;
    text-align: center;
  }

  .title {
    font-size: 30px;
    line-height: 100px;
    color: #f91d24;
    letter-spacing: 10px;
  }

  .icon1 {
    font-size: 50px;
    position: relative;
    left: -10px;
    bottom: -7px;
  }

  .button-cf {
    margin-top: 40px;
    margin-bottom: 20px;
  }

  >>> .el-table tr {
    text-align: left;
  }
</style>
